<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 按身高排序 -->
    <script>
      var sortPeople = function (names, heights) {
        let res = []
        let obj = {}
        // 将两个数组合并成以height[i]为key的集合
        for (let i = 0; i < heights.length; i++) {
          obj[heights[i]] = names[i]
        }

        // 利用集合默认根据key升序排序的特点，将name倒装进数组
        for (let key in obj) {
          res.unshift(obj[key])
        }

        return res
      }
      console.log(sortPeople(['Mary', 'John', 'Emma'], [180, 165, 170]))
    </script>
  </body>
</html>
